package com.aiyige.page.detail.adpater;

import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.model.Subject;
import com.aiyige.model.moment.entity.SingleVideo;
import com.aiyige.utils.TimeUtils;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.LinkedList;

/**
 * Created by zhuyakun on 2017/10/26.
 */

public class DetailSelectionAdapter extends BaseMultiItemQuickAdapter<SingleVideo, BaseViewHolder> {

    String subject = "";

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public DetailSelectionAdapter() {
        super(new LinkedList<SingleVideo>());
        addItemType(0, R.layout.item_detail_selection);
    }

    @Override
    protected void convert(BaseViewHolder helper, SingleVideo item) {

        helper.setVisible(R.id.iv_free, subject.equals(Subject.video_course) && item.isFree());
        if (item.isBuyed()) {//已买就不展示免费图标
            helper.setVisible(R.id.iv_free, false);
            helper.setVisible(R.id.tv_index,true);
        } else {
            helper.setVisible(R.id.tv_index,(subject.equals(Subject.video_course) && !item.isFree()) || subject.equals(Subject.video));
        }
        //        小于10前面加0
        String position = "";
        if (subject.equals(Subject.video_course)) {
            position = item.getIndex() < 10 ? ("0" + item.getIndex()) : item.getIndex() + "";
        } else {
            position = (helper.getAdapterPosition()+1) < 10 ? ("0" + (helper.getAdapterPosition()+1)) : (helper.getAdapterPosition()+1) + "";
        }
        helper.setText(R.id.tv_index, position+" ");

        helper.setText(R.id.tv_name, item.getTitle());
        helper.setText(R.id.tv_time, TimeUtils.getDurationTime(item.getDuration()));
        (helper.getView(R.id.tv_name)).setSelected(item.isSelected());
        ((TextView)(helper.getView(R.id.tv_name))).getPaint().setFakeBoldText(item.isSelected());
        helper.setVisible(R.id.iv_detail_selection_play, item.isSelected());
    }


}
